package models

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"zc2/appconfig"
)

var DB *gorm.DB

func Init() {
	data := appconfig.Config.Mysql
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8&parseTime=True&loc=Local", data.User, data.Pass, data.Host, data.Port, data.Database)
	//dsn := "root:3677bf6e037857724920065d38fc4c70@tcp(14.103.156.93:3306)/novel_website_db?charset=utf8&parseTime=True&loc=Local"
	var err error
	DB, err = gorm.Open(mysql.Open(dsn))
	if err != nil {
		panic(err)
	}
	DB.AutoMigrate(&User{}, &Xs{}, &Look{})
}
